package com.lyc.easyar.utils

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import java.io.BufferedInputStream
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.IOException

object BitmapUtil{
    /**
     * 将本地图片转成Bitmap
     * @param path 已有图片的路径
     * @return
     */
    fun openImage(path: String?): Bitmap? {
        var bitmap: Bitmap? = null
        try {
            val bis = BufferedInputStream(FileInputStream(path))
            bitmap = BitmapFactory.decodeStream(bis)
            bis.close()
        } catch (e: FileNotFoundException) {
            e.printStackTrace()
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return bitmap
    }


    fun revolveImageView(angle: Int, bitmap: Bitmap): Bitmap? {
        //旋转图片 动作
        val matrix = Matrix()
        matrix.postRotate(angle.toFloat())
        println("angle2=$angle")
        // 创建新的图片
        val resizedBitmap = Bitmap.createBitmap(
            bitmap, 0, 0,
            bitmap.width, bitmap.height, matrix, true
        )
        bitmap.recycle()
        return resizedBitmap
    }
}


